// 案例1：发号器
function * createIdMaker() {
    let id = 1;
    while(true) {
        yield id++
    }
}

const idMaker = createIdMaker();

console.log(idMaker.next().value);
console.log(idMaker.next().value);
console.log(idMaker.next().value);
console.log(idMaker.next().value);


// 案例2：改造iterator迭代器
const obj = {
    lift: ['吃饭', '睡觉','打豆豆'],
    learn: ['语文', '数学', '外语'],
    work: ['喝茶'],
    each: function(callback) {
        const all = [].concat(this.lift, this.learn, this.work);
        for(const item of all) {
            callback(item);
        }
    },
    [Symbol.iterator]: function * () {
        const all = [...this.lift, ...this.learn, this.work];
        for (const item of all) {
            yield item
        }
    }
}

for(const item of obj) {
    console.log(item)
}